{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count Odd Numbers in an Interval Range"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countOdds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #在区间范围内统计奇数数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个非负整数&nbsp;<code>low</code> 和&nbsp;<code>high</code>&nbsp;。请你返回<em>&nbsp;</em><code>low</code><em> </em>和<em>&nbsp;</em><code>high</code><em>&nbsp;</em>之间（包括二者）奇数的数目。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>low = 3, high = 7\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：</strong>3 到 7 之间奇数数字为 [3,5,7] 。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>low = 8, high = 10\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>8 到 10 之间奇数数字为 [9] 。</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= low &lt;= high&nbsp;&lt;= 10^9</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-odd-numbers-in-an-interval-range](https://leetcode.cn/problems/count-odd-numbers-in-an-interval-range/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-odd-numbers-in-an-interval-range](https://leetcode.cn/problems/count-odd-numbers-in-an-interval-range/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['3\\n7', '8\\n10']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        ans = (high-low) // 2\n",
    "        if high % 2 == 1 or low % 2 == 1:\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        ans = (high-low) // 2\n",
    "        if high % 2 == 1 or low % 2 == 1:\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        tmp = (high - low) // 2\n",
    "        if low % 2 == 1 or high % 2 == 1:\n",
    "            return tmp + 1\n",
    "        return tmp\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        pre = lambda x:(x+1)>>1\n",
    "        return pre(high)-pre(low-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if(low %2 !=0 and high %2 !=0):\n",
    "            return (high-low)//2+1\n",
    "        elif(low %2 !=0 and high %2 ==0):\n",
    "            return (high - low - 1) //2 +1\n",
    "        elif(low %2 ==0 and high %2 !=0):\n",
    "            return (high - low - 1) //2 +1\n",
    "        else:\n",
    "            return (high - low ) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if(low%2 or high%2):\n",
    "            return int((high-low)/2+1)\n",
    "        return math.floor((high-low)/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low%2==0 and high%2==0:\n",
    "            return(high-low+1)//2\n",
    "        elif low%2!=0 and high%2!=0:\n",
    "            return (high-low)//2+1\n",
    "        else:\n",
    "            # low%2!=0 and high%2!=0:\n",
    "            return (high-low-1)//2+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        pre = lambda x: (x + 1) >> 1\n",
    "        return pre(high) - pre(low - 1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if 0 == low % 2:\n",
    "            return 1 + (high - low - 1) // 2\n",
    "        else:\n",
    "            return 1 + (high - low) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        # counter = 0\n",
    "\n",
    "        # while low <= high:\n",
    "        #     if low % 2 != 0:\n",
    "        #         counter += 1\n",
    "\n",
    "        #     if high % 2 != 0:\n",
    "        #         counter += 1\n",
    "        #         if low == high:\n",
    "        #             counter -= 1\n",
    "            \n",
    "        #     low += 1\n",
    "        #     high -= 1\n",
    "        \n",
    "        # if counter <= 0:\n",
    "        #     return 0\n",
    "        # return counter\n",
    "\n",
    "        return ((high + 1) // 2) - (low // 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return round((high - 0.1 - low) / 2) if low % 2 == 0 and high % 2 == 0 else round((high - 0.1 - low) / 2) + 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low%2==0 and high%2==0:\n",
    "            return int((high-low)/2)\n",
    "        else:\n",
    "            return int((high-low)/2)+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 == 0 and high % 2 == 0:\n",
    "            return (high-low) // 2\n",
    "        elif low % 2 != 0 and high % 2 != 0:\n",
    "            return (high - 1 - low - 1) // 2 + 2\n",
    "        else:\n",
    "            return (high - 1 - low) // 2 + 1  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high + 1) // 2 - low // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        m = high // 2 + int(high % 2)\n",
    "        n = (low -1) // 2 + int((low-1) % 2) \n",
    "\n",
    "        return m - n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        m=high-low+1\n",
    "        if (low+high)%2!=0:\n",
    "            return int(m/2)\n",
    "        else:\n",
    "            if high%2==0:\n",
    "                return int(m//2)\n",
    "            else:\n",
    "                return int(m//2+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high - low) // 2 + (high % 2 == 1 or low % 2 == 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        n = (high - low )//2\n",
    "        if high % 2 == 1 and (high - low ) % 2 == 1:\n",
    "            return n + 1\n",
    "        if low % 2 == 0 :\n",
    "            return n\n",
    "        return n+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        pre=lambda x:(x+1)>>1\n",
    "        return pre(high)-pre(low-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 == 1 and high % 2 == 1:\n",
    "            n = (high - low ) // 2 + 1\n",
    "        else:\n",
    "            n = (high - low + 1) // 2\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high - low) // 2 + (high % 2 or low % 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        diff = high - low + 1\n",
    "        if diff % 2 == 0:\n",
    "            return diff // 2\n",
    "        else:\n",
    "            if low % 2 == 0:\n",
    "                return diff // 2\n",
    "            else:\n",
    "                return (diff // 2) + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high-low)//2+(low%2 or high%2);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low%2 == 0 and high%2 == 0:\n",
    "            return (high-low)//2\n",
    "        elif low%2 == 1 and high%2 == 1:\n",
    "            return (high-low)//2 + 1\n",
    "        else:\n",
    "            return (high-low+1)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        pre = lambda x: (x + 1) >> 1\n",
    "        return pre(high) - pre(low - 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if (high - low + 1) % 2  == 0:\n",
    "            return int(abs((high - low + 1)/2))\n",
    "        elif low % 2 == 1:\n",
    "            return  int(abs((high - low )/2) + 1)\n",
    "        else :\n",
    "            return int(abs((high - low )/2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high - low) // 2 + (low % 2 or high % 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high - low) // 2 + 1 if low % 2 != 0 or high % 2 != 0 else (high - low) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 == 0 and high % 2 == 0:\n",
    "            return int((high - low) / 2)\n",
    "        elif low % 2 != 0 and high % 2 != 0:\n",
    "            return int((high - low) / 2) + 1\n",
    "        else:\n",
    "            return int((high + 1 - low) / 2)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        pre = lambda x: (x + 1) >> 1\n",
    "        return pre(high) - pre(low - 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        count = None\n",
    "        if low%2 == 0 and high%2 == 0:\n",
    "            count = (high-low)/2\n",
    "            return int(count)\n",
    "        if low%2 != 0 and high%2 == 0:\n",
    "            count = (high-low+1)/2\n",
    "            return int(count)\n",
    "        if low%2 == 0 and high%2 != 0:\n",
    "            count = (high-low+1)/2\n",
    "            return int(count)\n",
    "        if low%2 != 0 and high%2 != 0:\n",
    "            count = (high-low)/2 + 1\n",
    "            return int(count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        pre=lambda x:(x+1)>>1\n",
    "        return pre(high)-pre(low-1)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low%2==1:\n",
    "            start=low\n",
    "        else :\n",
    "            start=low+1\n",
    "        if high%2==1:\n",
    "            end=high\n",
    "        else:\n",
    "            end=high-1\n",
    "        return int((end-start)/2+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        n=high-low+1\n",
    "        first,last=0,0\n",
    "        if low%2!=0:\n",
    "            first=1\n",
    "        if high%2!=0:\n",
    "            last=1\n",
    "        if first==1 and last==1:\n",
    "            return (n+1)//2\n",
    "        elif first==1 and last==0:\n",
    "            return n//2\n",
    "        elif first==0 and last==1:\n",
    "            return n//2\n",
    "        else :\n",
    "            return (n-1)//2\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high+1)//2-low//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high+1)//2-(low)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 == 0 and high %2 == 0:\n",
    "            return (high - low)//2\n",
    "        elif low % 2 != 0 and high % 2 != 0:\n",
    "            return (high - low - 1) // 2 + 2\n",
    "        else:\n",
    "            return (high - low - 1) // 2 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        num=high-low+1\n",
    "        if low%2==0 and high%2==0:\n",
    "            num=int(num/2)\n",
    "        elif low %2!=0 and high %2!=0:\n",
    "            num=int(num/2)+1\n",
    "        else:\n",
    "            num=num/2\n",
    "        return int(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        res = 0\n",
    "        sum = 0 \n",
    "        if low % 2 == 1:\n",
    "            low = low - 1\n",
    "        a = (high - low) // 2 \n",
    "        b =(high - low)% 2\n",
    "        res = a + b \n",
    "\n",
    "        return res \n",
    " \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        ca = high - low\n",
    "        if low %2 ==1 or high%2 == 1:\n",
    "            a = ca//2\n",
    "            return  a+1\n",
    "        else:\n",
    "            a = ca//2\n",
    "            return a "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high + 1) // 2 - low//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        count = 0\n",
    "        count = (high - low) // 2\n",
    "        if low % 2 == 1 or high%2 == 1:\n",
    "            count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        res = 0\n",
    "        if low % 2 == 0:\n",
    "            res += (high - low + 1) // 2\n",
    "        else:\n",
    "            res += (high - low) // 2 + 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        d = high - low\n",
    "        ans = 0\n",
    "        if low%2 == 0:\n",
    "            ans += (d+1)//2\n",
    "        else:\n",
    "            ans += 1 + d//2\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high - low) // 2 + (low % 2 or high % 2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        def f1(n):\n",
    "            if n % 2 == 0:\n",
    "                return n // 2\n",
    "            else:\n",
    "                return n // 2 + 1\n",
    "        \n",
    "        def f2(n):\n",
    "            return n // 2\n",
    "        \n",
    "        return f1(high) - f2(low)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        isum=(high-low)//2\n",
    "        if low%2==1 or high%2==1:\n",
    "            isum+=1\n",
    "        return isum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        a=0\n",
    "        b=0\n",
    "        if high%2==1:\n",
    "            b=high//2+1\n",
    "        if high%2==0:\n",
    "            b=high//2\n",
    "        a=low//2\n",
    "        return(b-a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        ans = 0\n",
    "        if high % 2 != 0 or low % 2 != 0:\n",
    "            return (high - low) // 2 + 1\n",
    "        return (high - low) // 2\n",
    "        #return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return round((high - 0.1 - low) / 2) if low % 2 == 0 and high % 2 == 0 else round((high - 0.1 - low) / 2) + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low%2+high%2>=1:\n",
    "            return (high-low)//2+1\n",
    "        return (high-low)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        n=(high-low)//2\n",
    "        j1=j2=False\n",
    "        if low%2==0:\n",
    "            j1=True\n",
    "        if high%2==0:\n",
    "            j2=True\n",
    "        if j1 and j2:\n",
    "            return n\n",
    "        else:\n",
    "            return n+1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if high -low == 1:\n",
    "            return 1\n",
    "        else:\n",
    "            count = 0\n",
    "        res = (high - low) // 2\n",
    "        if low % 2 == 0 and high % 2 == 0:\n",
    "            return  res \n",
    "        else: \n",
    "            return res + 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return ((high + 1)//2) - ((low) // 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        # 1 2 -> 1\n",
    "        # 1 2 3 -> 2\n",
    "        tot = high - low + 1\n",
    "        if tot & 1:\n",
    "            return int(high & 1) + tot // 2\n",
    "        else:\n",
    "            return tot // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        nums = high - low + 1\n",
    "        return nums // 2 + (nums % 2 == 1 and low % 2 == 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low%2!=0 or high%2!=0:\n",
    "            return (high-low)//2+1\n",
    "        else:\n",
    "            return (high-low)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 == 0 and high % 2 == 0:\n",
    "            return (high - low) // 2\n",
    "        if low % 2 == 1 and high % 2 == 1:\n",
    "            return ((high + 1) - (low - 1)) // 2\n",
    "        if low % 2 == 1 and high % 2 == 0:\n",
    "            return (high - (low - 1)) // 2\n",
    "        if low % 2 == 0 and high % 2 == 1:\n",
    "            return ((high + 1) - low) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 and high % 2:\n",
    "            return (high - low) // 2 + 1\n",
    "        return (high - low) // 2 + low % 2 + high % 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 == 0:\n",
    "            return (high - low + 1) // 2\n",
    "        else:\n",
    "            return (high - low) // 2 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low % 2 != 0:\n",
    "            return ((high-low)//2) + 1\n",
    "        else:\n",
    "            return (high-low+1)//2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        return (high + 1) // 2 - (low) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        import math\n",
    "        if low % 2 == 1:\n",
    "            return 1 + (high - low) // 2\n",
    "        else:\n",
    "            return math.ceil((high - low) / 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        count = 0\n",
    "        if high==low:\n",
    "            if high%2==0:\n",
    "                return 0\n",
    "            else:\n",
    "                return 1\n",
    "        elif high%2==low%2==1:\n",
    "            return int((high-low)/2)+1\n",
    "        elif high%2==low%2==0:\n",
    "            return int((high-low)/2)\n",
    "        elif high%2!=low%2:\n",
    "            return int((high-low+1)/2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        '''\n",
    "        n=high-low+1\n",
    "        first,last=0,0\n",
    "        if low%2!=0:\n",
    "            first=1\n",
    "        if high%2!=0:\n",
    "            last=1\n",
    "        if first==1 and last==1:\n",
    "            return (n+1)//2\n",
    "        elif first==1 and last==0:\n",
    "            return n//2\n",
    "        elif first==0 and last==1:\n",
    "            return n//2\n",
    "        else :\n",
    "            return (n-1)//2\n",
    "        '''\n",
    "        pre=lambda x:(x+1)>>1\n",
    "        return pre(high)-pre(low-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        match low%2==0 and high%2==0:\n",
    "            case True:\n",
    "                return int((high-low)/2)\n",
    "            case False:\n",
    "                return int((high-low)/2)+1\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if high % 2 == 1 and low % 2 ==1:\n",
    "            return int(((high-low)/2)+1)\n",
    "        if high % 2 == 0 and low % 2 ==0:\n",
    "            return int((high-low)/2)\n",
    "        else:\n",
    "            return int((high-low+1)/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        if low%2 == 0 and high%2 == 0:\n",
    "            return int((high-low)/2)\n",
    "        else:\n",
    "            return int((high-low)/2+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countOdds(self, low: int, high: int) -> int:\n",
    "        res = 0\n",
    "        if low % 2 == 0 and high % 2 == 0:\n",
    "            res = (high - low) // 2\n",
    "        else:\n",
    "            res = (high - low) // 2 + 1\n",
    "        return res"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
